package PAT;

import java.util.*;

class Node{
    String id ;

    public Node(String id) {
        this.id = id;
    }
}
public class PAT1032 {
    public static void main(String[] args) {
//        List<Node> nodes= new ArrayList<>();
        Set<String> ids = new HashSet<>();
        Scanner scanner = new Scanner(System.in);
        scanner.next();
        scanner.next();
        int n = scanner.nextInt();
        while (n-->0){
//            nodes.add (new Node(scanner.next()));
            scanner.next();
            scanner.next();
            String next = scanner.next();
            if(ids.contains(next)){
                System.out.println(next);
                return;
            }else{
                ids.add(next);
            }
        }
        System.out.println(-1);
    }
}
